CREATE PROCEDURE [dbo].[autoComplete_get_books]
    @searchPattern nvarchar(256) = null
AS
if(@searchPattern is not null)
BEGIN
    SELECT DISTINCT TOP(20) 
        [dbo].[Books].[BookId],
        [dbo].[Books].[Title]
    FROM [dbo].[Books]
    WHERE [dbo].[Books].[Title] LIKE '%' + @searchPattern + '%' 
          
END else
BEGIN
     SELECT TOP(20) 
       [dbo].[Books].[BookId],
        [dbo].[Books].[Title]
     FROM [dbo].[Books]
     ORDER BY [dbo].[Books].[Title]
END

RETURN 0
